package com.g8.pethospitallearnbackend.config;

import com.g8.pethospitallearnbackend.interceptors.AuthInterceptor;
import com.g8.pethospitallearnbackend.interceptors.JWTinterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//把配置类添加到ioc容器中
public class InterceptorConfig implements WebMvcConfigurer {

    //注入ioc容器中的LoginIntercopter拦截器
    @Autowired
    private JWTinterceptor jwTinterceptor;
    @Autowired
    private AuthInterceptor authInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 排除静态资源和登陆注册找回密码等接口
        registry.addInterceptor(jwTinterceptor)
                //拦截
//                .addPathPatterns("/user/test")
                // 登录和注册接口放行
                .excludePathPatterns("/self/login", "/self/signin", "/self/emailverify/**", "/self/newpassword/**")
                .excludePathPatterns("/css/**","/js/**","/images/**","/fonts/**");
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**","/js/**","/images/**","/fonts/**");
    }
}
